﻿using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace GeoSketch2.Archaeo
{
    /// <summary>
    /// The form which displays some information about an object
    /// Can add some comments
    /// </summary>
    public partial class ObjectInfosForm : Form
    {
        #region Fields
        BaseArchaeoDrawableObject CurrentObject;
        TObjectInfos CurrentTool; 
        #endregion

        #region Constructor
        /// <summary>
        /// The form which displays some information about an object
        /// Can add some comments
        /// </summary>
        /// <param name="Tool">The current information tool</param>
        public ObjectInfosForm(TObjectInfos Tool)
        {
            InitializeComponent();
            this.CurrentTool = Tool;
        } 
        #endregion

        #region Events
        void Button_OK_Click(object sender, EventArgs e)
        {
            CurrentObject.Comment = TextBox_Comment.Text;
            this.Hide();
            CurrentTool.SearchCommented();
        }

        /// <summary>
        /// Overrides the closing events, not disposing the form, just hiding it
        /// </summary>
        protected override void OnClosing(CancelEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
        }

        void Button_Cancel_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
        #endregion

        #region Properties
        /// <summary>
        /// Sets the object to display information about
        /// </summary>
        public BaseArchaeoDrawableObject Object
        {
            set
            {
                CurrentObject = value;
                ArchaeoProject Project = new ArchaeoProject(value.ExcavationArea.Project.SoilSheetModel);
                Project.ArchaeoObjects.Add(value);
                Project.MainSite.AvailableLayers.Add(value.Layer);

                DisplayBox.Viewport = new Viewport(DisplayBox, Project);
                DisplayBox.Viewport.CurrentObjectView = value.Bounds;
                DisplayBox.Viewport.Graphic.ResetClip();

                Label_Layer.Text = "Layer : " + value.Layer.Name;
                Label_Type.Text = "Type : " + value.GetType().ToString();
                Label_CreationTime.Text = "Creation Time : " + value.CreationTime.ToString("MMMM dd',' yyyy '-' HH:mm", Core.Vars.Setup.GeoSketch.NumberFormat);
                TextBox_Comment.Text = value.Comment;
            }
        } 
        #endregion
    }
}
